package org.dromara.app.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.bean.domain.vo.HisGoodsCarVo;
import org.dromara.bean.domain.bo.HisGoodsCarBo;
import org.dromara.bean.service.IHisGoodsCarService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 购物车
 *
 * @author Lion Li
 * @date 2024-12-25
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/goodsCar")
public class AHisGoodsCarController extends BaseController {

    private final IHisGoodsCarService hisGoodsCarService;


    /**
     * 查询购物车列表
     */
    @GetMapping("/list")
    public TableDataInfo<HisGoodsCarVo> list(HisGoodsCarBo bo, PageQuery pageQuery) {
        return hisGoodsCarService.queryPageList(bo, pageQuery);
    }


    /**
     * 新增购物车商品
     */
    @Log(title = "购物车商品", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HisGoodsCarBo bo) {
        return toAjax(hisGoodsCarService.insertByBo(bo));
    }

    /**
     * 修改购物车
     */
    @Log(title = "购物车", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HisGoodsCarBo bo) {
        return toAjax(hisGoodsCarService.updateByBo(bo));
    }

    /**
     * 删除购物车
     *
     * @param ids 主键串
     */
    @Log(title = "购物车", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(hisGoodsCarService.deleteWithValidByIds(List.of(ids), true));
    }
}
